package com.example.myapplication

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView


class DetailFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_detail, container, false)
    }

    @SuppressLint("SetTextI18n")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // 找到标题TextView并设置显示内容
        view.findViewById<TextView>(R.id.title).text = "新闻详情标题"
        // 找到内容TextView并设置显示详情内容
        view.findViewById<TextView>(R.id.content).text = "这是新闻的详细内容..."

        // 找到返回按钮并设置点击事件监听器
        view.findViewById<Button>(R.id.back_button).setOnClickListener {
            // 点击返回按钮时弹出Fragment回退栈，实现返回列表功能
            parentFragmentManager.popBackStack()
        }

    }
}